package com.penghaisoft.microwms.product.web.controller.outwarehouse;

import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.wms.model.ProScrapOutSn;
import com.penghaisoft.microwms.product.service.IProScrapOutSnService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/proscrapoutsn")
@Slf4j
public class ProScrapOutSnController extends BaseController {
	
		@Autowired
		private IProScrapOutSnService proScrapOutSnService;

	  /**
	   * 新增记录
	   * @param proscrapoutsn
	   * @return
	   */
		@PostMapping("c")
		public TransResult create(ProScrapOutSn proScrapOutSn) {
			proScrapOutSn.preInsert();
			Resp resp =  proScrapOutSnService.create(proScrapOutSn);
			return fromResp(resp);
		}

	  /**
	   * 删除记录（逻辑删除active_flag=0)
	   * @param proscrapoutsn
	   * @return
	   */
		@PostMapping("d")
		public TransResult delete(ProScrapOutSn proScrapOutSn) {
			proScrapOutSn.preUpdate();
			Resp resp =  proScrapOutSnService.delete(proScrapOutSn);
			return fromResp(resp);
		}

	  /**
	   * 查询列表
	   * @param proscrapoutsn
	   * @return
	   */
		@PostMapping("list")
		public TransResult list(@RequestParam(name = "page", defaultValue = "1") int page,
                            @RequestParam(name = "rows", defaultValue = "10") int rows,ProScrapOutSn proscrapoutsn) {
			Pager<ProScrapOutSn> result = proScrapOutSnService.findListByCondition(page,rows,proscrapoutsn);
			return success(result);
		}

	  /**
	   * 查询单条
	   * @param id
	   * @return
	   */
		@GetMapping("r/{id}")
		public TransResult queryById(@PathVariable String id) {
			ProScrapOutSn proScrapOutSn = proScrapOutSnService.findById(id);
			return success(proScrapOutSn);
		}

	  /**
	   * 修改记录
	   * @param proscrapoutsn
	   * @return
	   */
		@PostMapping("u")
		public TransResult update(ProScrapOutSn proScrapOutSn) {
			proScrapOutSn.preUpdate();
			Resp resp =  proScrapOutSnService.update(proScrapOutSn);
	    	return fromResp(resp);
		}
		
		@PostMapping("outOrder")
		public TransResult queryOrder(@RequestParam(name = "page", defaultValue = "1") int page,
	            @RequestParam(name = "rows", defaultValue = "10") int rows,ProScrapOutSn proscrapoutsn){
			Pager<ProScrapOutSn> result = proScrapOutSnService.queryOrder(page,rows,proscrapoutsn);
			
			String sumInfo = result.getOrder();
			if (sumInfo != null && sumInfo.length() > 0) {
				result.setOrder(sumInfo);
			}
			return success(result);
		}
	            
}
